<template>
    <div style="min-width:829px">
        <div v-if="$route.path == '/goodsDelivery'">
            <div class="vs-search-box">
                <el-form ref="form" v-search-box-enter :inline="true" :model="paging" label-width="110px">
                    <el-form-item label="关联单号：">
                        <el-input style="width:200px" placeholder="请输入关联单号" v-model="paging.ticket_code" clearable>
                            <i slot="prefix" class="el-input__icon el-icon-search"></i>
                        </el-input>
                    </el-form-item>
                    <el-form-item label="出库类型：">
                        <el-select style="width:160px" clearable v-model="paging.type" placeholder="请选择">
                            <el-option label="销售出库" value="1"> </el-option>
                            <el-option label="领用出库" value="2"> </el-option>
                            <el-option label="调拨出库" value="3"> </el-option>
                            <el-option label="积分商品出库" value="4"> </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="出库时间：">
                        <el-date-picker v-model="paging.date" type="daterange" format="yyyy-MM-dd"
                            value-format="yyyy-MM-dd" start-placeholder="开始时间" end-placeholder="结束时间"
                            style="width:300px">
                        </el-date-picker>
                    </el-form-item>
                    <el-form-item class="vs-right-btns">
                        <el-button @click="reset">重置</el-button>
                        <el-button @click="handleCurrentChange(1)" type="primary">查询</el-button>
                    </el-form-item>
                </el-form>
            </div>
            <div class="vs-table-box">
                <div class="operation-box clear-float">
                    <!-- <el-button @click="utils.goUrl('/goodsBeputInfo?type=2')" type="primary">新增</el-button> -->
                    <el-button v-if="utils.getIsShopowner()" @click="exportFn" icon="el-icon-download" type="primary">导出
                    </el-button>
                </div>
                <el-table v-loading="loading" :data="tableData" header-row-class-name="has-gutter-table"
                    style="width: 100%" border ref="multipleTable" @selection-change="handleSelectionChange"
                    @sort-change="sortChange">
                    <!-- <el-table-column type="selection" width="55" align="center"> </el-table-column> -->
                    <el-table-column width="100px" prop="id" label="序号" align="center"></el-table-column>
                    <el-table-column prop="type" label="出库类型" :formatter="typeFilter" min-width="130" align="center">
                    </el-table-column>
                    <el-table-column prop="number" label="出库单号" min-width="150" align="center"></el-table-column>
                    <el-table-column prop="ticket_code" label="关联要货单号" min-width="150" align="center"></el-table-column>
                    <el-table-column prop="count" label="出库数量" min-width="80" align="center"></el-table-column>
                    <el-table-column prop="total_price" v-if="utils.getIsShopowner()" label="出库金额" min-width="120"
                        align="center">
                        <template slot-scope="scope">
                            {{ (scope.row.total_price * 1).toFixed(2) }}
                        </template>
                    </el-table-column>
                    <el-table-column prop="create_time" label="出库时间" min-width="160" align="center"></el-table-column>
                    <el-table-column fixed="right" width="160" label="操作" align="center">
                        <template slot-scope="scope">
                            <span @click="setRow(1, scope.row)" class="tab-table-text">详情</span>
                        </template>
                    </el-table-column>
                </el-table>
                <div class="vs-paging-box">
                    <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page.sync="paging.page" :page-size="paging.limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="paging.total"
                        :page-sizes="[100, 200, 500, 1000]">
                    </el-pagination>
                </div>
            </div>
        </div>
        <router-view></router-view>
    </div>
</template>

<script>
export default {
    data() {
        return {
            shopList: [
                { label: '虹桥店', value: 0 },
                { label: '青浦店', value: 1 },
            ],
            loading: false,
            paging: {
                date: '',
                type: '',
                start_time: '',
                end_time: '',
                ticket_code: '',
                page: 1,
                total: 0,
                limit: 100,
            },
            tableData: [],
            multipleSelection: ''
        };
    },
    created() {
        if (this.$route.path == '/goodsDelivery') {
            this.handleCurrentChange(1);
        }
    },
    methods: {
        // 导出
        async exportFn() {
            let obj = Object.assign({}, this.paging);
            obj.start_time = obj.date ? obj.date[0] : '';
            obj.end_time = obj.date ? obj.date[1] : '';
            delete obj.date

            let url = this.utils.data.baseURL + 'store/stock/outstockListExport'
            this.utils.urlToBlob(url, "商品出库", obj)

            // let res = await this.$Http.outstockListExport(obj)
            // this.utils.downloadXlsx(res, "商品出库")
        },
        typeFilter(row) {
            let arr = ['', '销售出库', '领用出库', '调拨出库', '积分商城出库']
            return arr[row.type]
        },
        //排序
        sortChange(column) {
            console.log(column);
            // this.form.sort = column.prop
            // this.form.sort_type = column.order == 'ascending' ? 'up' : 'down'
            // this.getHouseList()
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
            console.log(this.multipleSelection);
        },
        async setRow(type, row) {
            if (type == 1) {
                this.utils.goUrl('/goodsDeliveryInfo?type=' + row.type + '&ticket_code=' + row.ticket_code + "&number=" + row.number + "&create_time=" + row.create_time)
            }
        },
        async repairGetList() {
            this.loading = true;
            let obj = Object.assign({}, this.paging);
            obj.start_time = obj.date ? obj.date[0] : '';
            obj.end_time = obj.date ? obj.date[1] : '';
            delete obj.date
            let { code, data } = await this.$Http.outstockList(obj);
            this.loading = false;
            if (code) {
                this.tableData = data.data;
                this.paging.total = data.total;
            }
        },
        reset() {//重置
            this.paging = this.$options.data().paging;
            // this.form.date = '';
            this.handleCurrentChange(1)
        },
        handleSizeChange(val) {
            this.paging.limit = val;
            this.repairGetList()
        },
        handleCurrentChange(val) {
            this.paging.page = val;
            this.repairGetList()
        }
    },
};
</script>

<style lang="scss" scoped>
.image-thumbnail {
    width: 130px;
    height: 130px;
}
</style>